package cn.csust.net2.manager.server.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.csust.net2.manager.server.dao.BaseDAO;
import cn.csust.net2.manager.server.remote.BeanUtils;
import cn.csust.net2.manager.shared.exception.BeyondAuthorityException;
import cn.csust.net2.manager.shared.po.PO;
import cn.csust.net2.manager.shared.po.User;
import cn.csust.net2.manager.shared.service.InnerMailService;
import cn.csust.net2.manager.shared.util.ServiceConstant;
import com.extjs.gxt.ui.client.data.BasePagingLoadResult;
import com.extjs.gxt.ui.client.data.PagingLoadConfig;

@Service(value = ServiceConstant.SERVICE_NAME_INNERMAIL)
public class InnerMailServiceImpl extends BaseServiceImpl  implements  InnerMailService{
	/**
	 * 根据条件查找全部
	 * 初始加载数据是根据当前用户进行加载
	 */

	@Transactional
	@Override
	public <T extends PO>  BasePagingLoadResult<T> findAll(String cla,PagingLoadConfig config)throws BeyondAuthorityException{
		User user = config.get("user");

		BaseDAO<T> dao = BeanUtils.getBean(cla);
		if(user!=null){
			String  hql = "from InnerMail c where c.receiver.userID = " + user.getUserID();
			return dao.findAllByPaging(config, hql);
		}
		else
			return dao.findAllByPaging(config);

	}

}
